<?php
// +----------------------------------------------------------------------
// | PHP [ JUST YOU ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2017 http://www.jyphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: FlyingPig <flyingpigfp@163.com>
// +----------------------------------------------------------------------

namespace App\Model\User;


use App\Model\Base;
use Illuminate\Support\Facades\DB;

class UserDiscountInfo extends Base
{

    protected $table = 't_discount_info';

    protected $appends = ['desc', 'name', 'type', 'sign'];


    public function getDescAttribute()
    {
        $type = DB::table('t_quickly_grab_info')->where('id', $this->match_id)->value('type');
        if ($type == 1) {
            if ($this->reward_type == 1) {
                $quan = '特惠券';
            } else {
                $quan = '优惠券';
            }
            return "恭喜您获得{$this->name}{$quan}，验证码：{$this->code}，请前往微信公众号中使用！点击”使用”可查看使用流程。";
        } elseif ($type == 2) {
            if ($this->reward_type == 1) {
                return "恭喜您获得{$this->name}，验证码：{$this->code}，请前往微信公众号中使用！点击”使用”可查看使用流程。";
            } else {
                return "恭喜您获得商城通用优惠券，验证码：{$this->code}，请前往微信公众号中使用！点击”使用”可查看使用流程。";
            }
        }

    }

    public function getNameAttribute()
    {
        return DB::table('t_quickly_grab_info')->where('id', $this->match_id)->value('name') ?? '';
    }

    public function getTypeAttribute()
    {
        return $this->reward_type;
    }

    public function getSignAttribute()
    {
        return $this->code;
    }

    public function getIdAttribute()
    {
        $type = DB::table('t_quickly_grab_info')->where('id', $this->match_id)->value('type');
        if ($type == 2 && $this->reward_type == 1) {
            return 16;
        }
        if ($type == 1 && $this->reward_type == 1) {
            return 14;
        }
        return 15;
    }

}